package net.adetech.crj.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.adetech.crj.common.Contant;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class Apply implements Serializable {

    private long applyId;
    private String applyUserId;
    private String idType;
    private String idNumber;
    private String realName;
    private String applyNo;
    private String applySummary;
    private String applyDetail;
    private Timestamp applyTime;
    private String applyState;
    private String dataState;
    private String phoneNumber;
    private long appointmentId;
    private String remindJson;

    public long getAppointmentId() {
        return appointmentId;
    }

    public void setAppointmentId(long appointmentId) {
        this.appointmentId = appointmentId;
    }

    private List<ApplySummary> summary;


    public long getApplyId() {
        return applyId;
    }

    public void setApplyId(long applyId) {
        this.applyId = applyId;
    }

    public String getApplyUserId() {
        return applyUserId;
    }

    public void setApplyUserId(String applyUserId) {
        this.applyUserId = applyUserId;
    }

    public String getIdType() {
        return idType;
    }

    public void setIdType(String idType) {
        this.idType = idType;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }


    public String getApplyNo() {
        return applyNo;
    }

    public void setApplyNo(String applyNo) {
        this.applyNo = applyNo;
    }

    public String getApplySummary() {
        return applySummary;
    }

    public void setApplySummary(String applySummary) {
        this.applySummary = applySummary;
    }

    public String getApplyDetail() {
        return applyDetail;
    }

    public void setApplyDetail(String applyDetail) {
        this.applyDetail = applyDetail;
    }

    public Timestamp getApplyTime() {
        return applyTime;
    }

    public void setApplyTime(Timestamp applyTime) {
        this.applyTime = applyTime;
    }

    public String getApplyState() {
        return applyState;
    }

    public void setApplyState(String applyState) {
        this.applyState = applyState;
    }

    public String getDataState() {
        return dataState;
    }

    public void setDataState(String dataState) {
        this.dataState = dataState;
    }

    public void setSummary(List<ApplySummary> summary) {
        this.summary = summary;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public List<ApplySummary> getSummary() {
        this.initSummary();

        return this.summary;
    }

    public void initSummary() {
        List<ApplySummary> applySummaryList = new ArrayList<ApplySummary>();
        if (this.applySummary != null) {
            if ("A".equals(this.applySummary)) {
                JSONObject formObject = JSONObject.parseObject(this.applyDetail);
                JSONArray qwdArray = formObject.getJSONArray("qwd");
                JSONArray sqlbArray = formObject.getJSONArray("sqlb");

                if (sqlbArray.contains("101")) {
                    ApplySummary summary = new ApplySummary();
                    summary.setTitle("普通护照");
                    String info = Contant.bzlbMap.get(formObject.getString("bzlbHz"));
                    summary.setInfo(info);
                    applySummaryList.add(summary);
                }
                if (sqlbArray.contains("102")) {
                    ApplySummary summary = new ApplySummary();
                    summary.setTitle("往来港澳通行证");
                    String info = Contant.bzlbMap.get(formObject.getString("bzlbGa"));
                    summary.setInfo(info);
                    applySummaryList.add(summary);
                }
                if (qwdArray.contains("HKG")) {
                    String qzzl = formObject.getString("qzzlHkg");
                    String qzcs = formObject.getString("qzcsHkg");

                    String qzzlString = Contant.qzzlMap.get(qzzl);
                    String qzcsString = Contant.qzcsMap.get(qzcs);
                    String info = qzzlString;
                    if (qzcsString != null) {
                        info += "  " + qzcsString;
                    }
                    ApplySummary summary = new ApplySummary();
                    summary.setTitle("往来香港签注");
                    summary.setInfo(info);
                    applySummaryList.add(summary);


                }
                if (qwdArray.contains("MAC")) {
                    String qzzl = formObject.getString("qzzlMac");
                    String qzcs = formObject.getString("qzcsMac");

                    String qzzlString = Contant.qzzlMap.get(qzzl);
                    String qzcsString = Contant.qzcsMap.get(qzcs);
                    String info = qzzlString;
                    if (qzcsString != null) {
                        info += "  " + qzcsString;
                    }
                    ApplySummary summary = new ApplySummary();
                    summary.setTitle("往来澳门签注");
                    summary.setInfo(info);
                    applySummaryList.add(summary);
                }
                if (sqlbArray.contains("104")) {
                    ApplySummary summary = new ApplySummary();
                    summary.setTitle("往来台湾通行证");
                    String info = Contant.bzlbMap.get(formObject.getString("bzlbTw"));
                    summary.setInfo(info);
                    applySummaryList.add(summary);
                }
                if (qwdArray.contains("TWN")) {
                    String qzzl = formObject.getString("qzzlTwn");
                    String qzcs = formObject.getString("qzcsTwn");

                    String qzzlString = Contant.qzzlMap.get(qzzl);
                    String qzcsString = Contant.qzcsMap.get(qzcs);
                    String info = qzzlString;
                    if (qzcsString != null) {
                        info += "  " + qzcsString;
                    }
                    ApplySummary summary = new ApplySummary();
                    summary.setTitle("往来台湾签注");
                    summary.setInfo(info);
                    applySummaryList.add(summary);
                }


            }

            if ("B".equals(this.applySummary)) {
                JSONObject formObject = JSONObject.parseObject(this.applyDetail);

                String sqlb = formObject.getString("sqlb");
                String bzlx = formObject.getString("bzlx");
                ApplySummary applySummary = new ApplySummary();
                String titlePrefix = "申请";
                if ("W1".equals(bzlx)) {
                    titlePrefix = "";
                    applySummary.setInfo("申请");
                } else if ("W2".equals(bzlx)) {
                    applySummary.setInfo("延期");
                } else if ("W3".equals(bzlx)) {
                    applySummary.setInfo("补发");
                } else if ("W4".equals(bzlx)) {
                    applySummary.setInfo("换发");
                }
                if ("202".equals(sqlb)) {
                    applySummary.setTitle(titlePrefix+"普通签证");
                } else if ("205".equals(sqlb)) {
                    applySummary.setTitle(titlePrefix+"居留许可");
                } else if ("207".equals(sqlb)) {
                    applySummary.setTitle(titlePrefix+"停留证件");
                }



                applySummaryList.add(applySummary);
            }
        }

        this.summary = applySummaryList;
    }


    public class ApplySummary {
        private String title;
        private String info;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getInfo() {
            return info;
        }

        public void setInfo(String info) {
            this.info = info;
        }
    }

    public String getRemindJson() {
        return remindJson;
    }

    public void setRemindJson(String remindJson) {
        this.remindJson = remindJson;
    }

    public boolean getHasRemind()
    {
        return this.getRemindList()!=null && this.getRemindList().size()>0;
    }

    public JSONArray getRemindList()
    {
        if (this.remindJson!=null)
        {
            return JSONArray.parseArray(this.remindJson);
        }
        else {
            return null;
        }
    }




    //    public List<String> getTips()
//    {
//        List<String> tipsList = new ArrayList<String>();
//        if (this.applySummary!=null)
//
//
//        return  tipsList;
//    }
}
